﻿<!DOCTYPE>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	//获得本项目的地址(例如: http://localhost:8080/MyApp/)赋值给basePath变量 
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("basePath", basePath);
	pageContext.setAttribute("path", path);
%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${basePath}css/style.css" />
<link rel="stylesheet" type="text/css"
	href="${basePath}css/external.min.css" />
<link rel="stylesheet" type="text/css" href="${basePath}css/popup.css" />
<script type="text/javascript" src="${basePath}js/jquery-3.2.1.js"></script>
<title>修改密码</title>
<meta content="description" name="description">
<meta content="keywords" name="keywords">
</head>

<body>
	<div id="body">
		<%@include file="../header.jsp"%>
		<!-- end #header -->
		<div id="container">
			<div class="content user_modifyContent">
				<dl class="c_section">
					<dt>
						<h2>
							<em></em>修改密码
						</h2>
					</dt>
					<dd>
						<form id="updatePswForm">
							<table class="savePassword">
								<tbody>
									<tr>
										<td>登录邮箱</td>
										<td class="c7">${sessionScope.user.userEmail}</td>
									</tr>
									<tr>
										<td class="label">当前密码</td>
										<td>
											<input type="password" value="" maxlength="16" id="oldpassword" name="oldpassword">
										</td>
									</tr>
									<tr>
										<td class="label">新密码</td>
										<td>
											<input type="password" value="" maxlength="16" id="newpassword" name="newpassword">
										</td>
									</tr>
									<tr>
										<td class="label">确认密码</td>
										<td>
										<input type="password" maxlength="16" value=""
											id="comfirmpassword" name="comfirmpassword">
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td><a href="javascript:check();" title="保存" class="btn_32">保存</a></td>
									</tr>
								</tbody>
							</table>
						</form>
					</dd>
				</dl>
			</div>
			
</body>
<script type="text/javascript">
function check(){
	var oldpassword = $("#oldpassword").val();
	var newpassword = $("#newpassword").val();
	var comfirmpassword = $("#comfirmpassword").val();
	if(newpassword.length < 6 || newpassword.length > 16){alert("新设置密码长度，应该在 6-16 之间");return;}
	if(newpassword != comfirmpassword){alert("输入的2次新密码不同");return;}
	$.ajax({
		type : 'POST',
		data : {
			oldpassword : oldpassword,
			newpassword : newpassword,
		},
		url : '${basePath}user/updateUserPwd',
		dataType : 'json',
		success : function(result) {
			console.log("success");
			var model = result.model;
			if (model.code == 0) {
				console.log(model.msg);
				window.location.href = "${basePath}" + model.href;
			} else {
				alert(model.msg);
				console.log(model.msg);
			}
		}
	});
}
</script>
</html>